package com.example.a429;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;

public class MainActivity1 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main1);

        RecyclerView recyclerView = findViewById(R.id.recommendation_recycler);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        List<RecommendationItem> recommendationList = new ArrayList<>();
        recommendationList.add(new RecommendationItem(R.drawable.iphone_13_pro, "iPhone 13 Pro", 5999));
        recommendationList.add(new RecommendationItem(R.drawable.sony_wh_1000xm4, "Sony WH - 1000XM4", 2299));
        recommendationList.add(new RecommendationItem(R.drawable.airpods, "AirPods", 1799));

        RecommendationAdapter adapter = new RecommendationAdapter(recommendationList);
        recyclerView.setAdapter(adapter);
    }
    public void onBackButtonClick(View view) {
        // 调用系统的返回方法
        onBackPressed();
    }

    public void contactSeller(View view) {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        intent.setData(Uri.parse("tel:卖家电话号码"));
        startActivity(intent);
    }

    public void favoriteProduct(View view) {

    }

    public void shareProduct(View view) {
        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        shareIntent.putExtra(Intent.EXTRA_TEXT, "快来看看这款MacBook Pro 2021 M1 Pro");
        startActivity(Intent.createChooser(shareIntent, "分享"));
    }

    public void buyNow(View view) {
        Intent intent = new Intent(this, RecommendationDetailActivity.class);
        startActivity(intent);
    }
}